Page({
  data: {
    text1: '上午3.5小时：',
    text2: '  --用时：',
    text3: 'h。',
    text4: '下午4.5小时：',
    text5: '  --用时：',
    text6: 'h。',
    textList1:[],
    textList2:[],
    timeTxt1:['0'],
    timeTxt2:['0'],
    lists1:[1],
    lists2:[1],
    inputNum1:1,
    inputNum2:1,
    options: [{
      city_id: '0.5',
      city_name: '0.5'
    }, {
      city_id: '1',
      city_name: '1'
    }, {
      city_id: '1.5',
      city_name: '1.5'
    }, {
      city_id: '2',
      city_name: '2'
    }, {
      city_id: '2.5',
      city_name: '2.5'
    }, {
      city_id: '3',
      city_name: '3'
    }, {
      city_id: '3.5',
      city_name: '3.5'
    }, {
      city_id: '4',
      city_name: '4'
    }, {
      city_id: '4.5',
      city_name: '4.5'
    }],
    selected: {},
  },
  change (e) {
    this.setData({
      selected: { ...e.detail }
    })
    wx.showToast({
      title: `${this.data.selected.id} - ${this.data.selected.name}`,
      icon: 'success',
      duration: 1000
    })
  },
  close () {
    // 关闭select
    this.selectComponent('#select').close()
  },
  addList1: function(){
    var lists1 = this.data.lists1;
    var lists2 = this.data.lists2;
    var timeTxt1 = this.data.timeTxt1;
    var inputNum1 = this.data.inputNum1+1;
    if((lists1.length+lists2.length)>6){
      wx.showToast({
        title: '超过上限',
        icon: 'none',
        duration: 2000//持续的时间
      })
    }else{
    var newData = lists1.length+1;
    lists1.push(newData);//实质是添加lists数组内容，使for循环多一次
    timeTxt1.push(0);
    this.setData({
      lists1: lists1,
      inputNum1:inputNum1,
      timeTxt1:timeTxt1,
    })  
  }
  },
  addList2: function(){
    var lists1 = this.data.lists1;
    var lists2 = this.data.lists2;
    var timeTxt2 = this.data.timeTxt2;
    var inputNum2 = this.data.inputNum2+1;
    if((lists1.length+lists2.length)>50){
      wx.showToast({
        title: '超过上限',
        icon: 'none',
        duration: 2000//持续的时间
      })
    }else{
    var newData = lists2.length+1;
    lists2.push(newData);//实质是添加lists数组内容，使for循环多一次
    timeTxt2.push(0);
    this.setData({
      lists2: lists2,
      inputNum2:inputNum2,
      timeTxt2:timeTxt2,
    })  
  }
  },
  delList1: function () {
    var lists1 = this.data.lists1;
    var textList1 = this.data.textList1;
    var timeTxt1 = this.data.timeTxt1;
    var tmp = this.data.inputNum1;
    var inputNum1 =0;
    if(tmp != 0){
    inputNum1 = this.data.inputNum1-1;}
    if(textList1.length >=lists1.length){
    textList1.pop();
  }
    lists1.pop();      //实质是删除l   ists数组内容，使for循环少一次
    timeTxt1.pop();
    this.setData({
      lists1: lists1,
      textList1:textList1,
      inputNum1:inputNum1,
      timeTxt1:timeTxt1,
    })
  }, 
  delList2: function () {
    var lists2 = this.data.lists2;
    var textList2 = this.data.textList2;
    var timeTxt2 = this.data.timeTxt2;
    var tmp = this.data.inputNum2;
    var inputNum2 =0;
    if(tmp != 0){
    inputNum2 = this.data.inputNum2-1;}
    if(textList2.length >=lists2.length){
    textList2.pop();
  }
    lists2.pop();      //实质是删除l   ists数组内容，使for循环少一次
    timeTxt2.pop();
    this.setData({
      lists2: lists2,
      textList2:textList2,
      inputNum2:inputNum2,
      timeTxt2:timeTxt2,
    })
  }, 

  bindKeyInput1: function(e){
    var id =  e.currentTarget.id;
    var a = e.detail.value;
    var textList1 = this.data.textList1;
    var inputNum1 = this.data.inputNum1;
    if(inputNum1==textList1.length){
    textList1[id-1] = a;
    }else{
    textList1.push(a)};
    this.setData({
      textList1: textList1,
    })
  },
  bindKeyInput2: function(e){
    var id =  e.currentTarget.id;
    var a = e.detail.value;
    var textList2 = this.data.textList2;
    var inputNum2 = this.data.inputNum2;
    if(inputNum2==textList2.length){
    textList2[id-1] = a;
    }else{
    textList2.push(a)};
    this.setData({
      textList2: textList2,
    })
  },
  getData1:function(e){
    var id = e.currentTarget.dataset.id;
    var t1 = e.detail.id;
    var timeTxt1 = this.data.timeTxt1;
    var list1 = this.data.lists1;
    if(timeTxt1.length<list1.length){
      timeTxt1.push[t1];
    }else{
      timeTxt1[id-1]=t1;
    }
    this.setData({
      timeTxt1:timeTxt1,
    });
  },
  getData2:function(e){
    var id = e.currentTarget.dataset.id;
    var t2 = e.detail.id;
    var timeTxt2 = this.data.timeTxt2;
    var list2 = this.data.lists2;
    if(timeTxt2.length<list2.length){
      timeTxt2.push[t2];
    }else{
      timeTxt2[id-1]=t2;
    }
    this.setData({
      timeTxt2:timeTxt2,
    });
  },
  show: function(e){
    var text1 = this.data.text1;
    var text2 = this.data.text2;
    var text3 = this.data.text3;

    var text4 = this.data.text4;
    var text5 = this.data.text5;
    var text6 = this.data.text6;


    var textList1 = this.data.textList1;
    var timeTxt1 = this.data.timeTxt1;

    var textList2 = this.data.textList2;
    var timeTxt2 = this.data.timeTxt2;
    var res= text1+'\r\n';
    for(var i=0;i<textList1.length;i++){
      res+=textList1[i]+text2+timeTxt1[i]+text3+'\r\n';
    };

    res += text4+'\r\n';
    for(var i=0;i<textList2.length;i++){
      res+=textList2[i]+text5+timeTxt2[i]+text6+'\r\n';
    };
    wx.setClipboardData({
      data: res,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功', //提示消息
              icon: 'none',
              duration: 2000//持续的时间
            })
            }
          })}
        })
  }
})